#!/bin/sh

set -eu

main() {
  if [ $# -ne 0 ]; then
    for lus_; do
      run_test "$lus_"
    done
    return
  fi

  for lus_ in tests/translate/*.lus; do
    run_test "$lus_"
  done
}

run_test() {
  lus_="$1"
  c_=${lus_%.lus}.c
  err_=${lus_%.lus}.err

  if [ -f "$err_" ]; then
    if run_st0 translate "$lus_" "$c_" 2>"$err_"; then
      echo "$lus_ should fail"
      exit 1
    else
      rm "$c_"
    fi
    return
  fi

  run_st0 translate "$lus_" "$c_"
}

run_st0() {
  ./build/bin/luster_st0 "$@"
}

main "$@"
